module.exports = function(window, document) {
	var apivm = require('../../common/avm.min')(window, document);
	var avm = apivm;
	var api = apivm.api;
	var Component = apivm.Component;
	var $ = apivm.$;
	(function() {
	var Tabbar = /*@__PURE__*/ (function(Component) {
		function Tabbar(props) {
			Component.call(this, props);
			this.data = {};
		}

		if (Component) Tabbar.__proto__ = Component;
		Tabbar.prototype = Object.create(Component && Component.prototype);
		Tabbar.prototype.constructor = Tabbar;
		Tabbar.prototype.apiready = function() {};
		Tabbar.prototype.goPage = function(pagename) {
			var pagePath = {
				index: "../index/index",
				friend: "../friend/friend",
				addVideo: "../addVideo/addVideo",
				message: "../message/message",
				me: "../me/me"
			};

			// api.openWin({
			// 	name: pagename,
			// 	url: pagePath[pagename]
			// })
			wx.redirectTo({url: pagePath[pagename]});
		};
		Tabbar.prototype.render = function() {
			var this$1 = this;
			return apivm.h(
				"view",
				{class: "tabbar"},
				apivm.h(
					"view",
					{
						class: "tab-item",
						style: {color: this.props.active == "index" ? "#fff" : "#ccc"},
						onClick: function() {
							return this$1.goPage("index");
						}
					},
					"首页"
				),
				apivm.h(
					"view",
					{
						class: "tab-item",
						style: {color: this.props.active == "friend" ? "#fff" : "#ccc"},
						onClick: function() {
							return this$1.goPage("friend");
						}
					},
					"朋友"
				),
				apivm.h(
					"view",
					{
						class: "tab-item",
						onClick: function() {
							return this$1.goPage("addVideo");
						}
					},
					apivm.h("image", {src: "../../image/add.png"})
				),
				apivm.h(
					"view",
					{
						class: "tab-item",
						style: {color: this.props.active == "message" ? "#fff" : "#ccc"},
						onClick: function() {
							return this$1.goPage("message");
						}
					},
					"消息"
				),
				apivm.h(
					"view",
					{
						class: "tab-item",
						style: {color: this.props.active == "me" ? "#fff" : "#ccc"},
						onClick: function() {
							return this$1.goPage("me");
						}
					},
					"我"
				)
			);
		};

		return Tabbar;
	})(Component);
	apivm.define("tabbar", Tabbar);

	var Test = /*@__PURE__*/ (function(Component) {
		function Test(props) {
			Component.call(this, props);
			this.data = {
				dataList: ["item1", "item2", "item3", "item4"],
				num: 0,
				videoList: [
					{
						id: "000",
						nickname: "老陈打码",
						content: "新年快乐,万事如意",
						src: "https://a415432669.github.io/shortvideo/000.mp4",
						like: "3.5w",
						share: "3821",
						collect: "2988",
						comment: "3478",
						isLike: false,
						pubtime: "2021-12-31 01:07",
						headimg: "https://a415432669.github.io/shortvideo/000.jpg"
					},
					{
						id: "001",
						nickname: "学习通知",
						content: "快乐学习APICloud多端应用开发",
						src: "https://a415432669.github.io/shortvideo/001.mp4",
						like: "2.5w",
						share: "3821",
						collect: "2988",
						comment: "3478",
						isLike: true,
						pubtime: "2021-12-31 01:07",
						headimg: "https://a415432669.github.io/shortvideo/001.jpg"
					},
					{
						id: "002",
						nickname: "小庆幸",
						content: "感谢每一个为我们打开世界的人",
						src: "https://a415432669.github.io/shortvideo/002.mp4",
						like: "1.8w",
						share: "3221",
						collect: "2988",
						comment: "3478",
						isLike: false,
						pubtime: "2021-12-31 01:07",
						headimg: "https://a415432669.github.io/shortvideo/002.jpg"
					},

					{
						id: "003",
						nickname: "琪琪",
						content: "当你来到这个世界，他就拥有超能力！致伟大的父亲",
						src: "https://a415432669.github.io/shortvideo/003.mp4",
						like: "7.7w",
						share: "7821",
						collect: "2988",
						comment: "3478",
						isLike: false,
						pubtime: "2021-12-31 01:07",
						headimg: "https://a415432669.github.io/shortvideo/003.jpg"
					}
				],

				current: 0,
				isShow: "flex"
			};
		}

		if (Component) Test.__proto__ = Component;
		Test.prototype = Object.create(Component && Component.prototype);
		Test.prototype.constructor = Test;
		Test.prototype.apiready = function() {
			var this$1 = this;

			document
				.querySelector("#video" + this.data.current)
				.$$getContext()
				.then(function(context) {
					this$1.videoContext = context;
					context.play();
				});
		};
		Test.prototype.onchange = function(e) {
			var this$1 = this;

			this.data.current = e.detail.current;
			console.log(this.data.current);
			// this.videoContext && this.videoContext.pause()
			// this.videoContext = wx.createVideoContext('video' + this.current)
			// console.log(this.videoContext)
			// this.videoContext.play()
			console.log(this.data.videoList.length);
			if (this.data.current == this.data.videoList.length - 1) {
				this.data.videoList.push({
					id: "004",
					nickname: "悦悦宝宝",
					content: "虎年大吉，虎虎生财好运来！",
					src: "https://a415432669.github.io/shortvideo/004.mp4",
					like: "2.2w",
					share: 3821,
					collect: 2688,
					comment: 3478,
					isLike: false,
					pubtime: "2021-12-31 01:07",
					headimg: "https://a415432669.github.io/shortvideo/004.jpg"
				});

				console.log(this.data.videoList);
			}
			this.videoContext && this.videoContext.pause();
			document
				.querySelector("#video" + this.data.current)
				.$$getContext()
				.then(function(context) {
					this$1.videoContext = context;
					context.play();
				});
		};
		Test.prototype.play = function() {
			this.data.isShow = "none";
		};
		Test.prototype.pause = function() {
			this.data.isShow = "flex";
		};
		Test.prototype.togglePlay = function(index) {
			console.log(this.videoContext);
			if (this.data.isShow == "flex") {
				this.videoContext.play();
				this.data.isShow = "none";
			} else {
				this.videoContext.pause();
				this.data.isShow = "flex";
			}
		};
		Test.prototype.ended = function() {
			this.videoContext.play();
		};
		Test.prototype.likeFn = function() {
			this.data.videoList[this.data.current].isLike = !this.data.videoList[
				this.data.current
			].isLike;
		};
		Test.prototype.shareFn = function() {
			this.data.videoList[this.data.current].share =
				parseInt(this.data.videoList[this.data.current].share) + 1;
		};
		Test.prototype.render = function() {
			var this$1 = this;
			return apivm.h(
				"scroll-view",
				{class: "main", "scroll-y": true},

				apivm.h(
					"swiper",
					{class: "swiper", circular: true, vertical: true, onChange: this.onchange},
					Object.entries(this.data.videoList).map(function(ref) {
						var _index = ref[0];
						var _item = ref[1];
						return apivm.h(
							"swiper-item",
							{class: "swiper-item"},

							apivm.h("video", {
								controls: false,
								class: "video",
								src: _item.src,
								mode: "aspectFit",
								id: "video" + _index,
								onplay: function(event) {
									if (this$1.play) {
										this$1.play(event);
									} else {
										play(event);
									}
								},
								onpause: function(event) {
									if (this$1.pause) {
										this$1.pause(event);
									} else {
										pause(event);
									}
								},
								onended: function(event) {
									if (this$1.ended) {
										this$1.ended(event);
									} else {
										ended(event);
									}
								},
								onclick: function(event) {
									if (this$1.togglePlay) {
										this$1.togglePlay(event);
									} else {
										togglePlay(event);
									}
								}
							})
						);
					})
				),

				apivm.h(
					"div",
					{class: "rightBar"},
					apivm.h(
						"view",
						{class: "right-item", onClick: this.likeFn},
						this.data.videoList[this.data.current].isLike
							? apivm.h("image", {src: "../../image/heart_active.png"})
							: apivm.h("image", {src: "../../image/heart.png"}),

						apivm.h("text", null, this.data.videoList[this.data.current].like)
					),
					apivm.h(
						"view",
						{class: "right-item"},
						apivm.h("image", {src: "../../image/comment.png"}),
						apivm.h("text", null, this.data.videoList[this.data.current].comment)
					),
					apivm.h(
						"view",
						{class: "right-item"},
						apivm.h("image", {src: "../../image/collect.png"}),
						apivm.h("text", null, this.data.videoList[this.data.current].collect)
					),
					apivm.h(
						"view",
						{class: "right-item"},
						apivm.h("image", {src: "../../image/share.png", onClick: this.shareFn}),
						apivm.h("text", null, this.data.videoList[this.data.current].share)
					)
				),

				apivm.h(
					"view",
					{
						class: "playBtn",
						style: {display: this.data.isShow},
						onClick: this.togglePlay
					},
					apivm.h("image", {src: "../../image/pause.png"})
				),
				apivm.h(
					"view",
					{class: "desc"},
					apivm.h(
						"view",
						{class: "nickname"},
						"@",
						this.data.videoList[this.data.current].nickname
					),
					apivm.h(
						"view",
						{class: "content"},
						this.data.videoList[this.data.current].content
					)
				),
				apivm.h("tabbar", {active: "index"})
			);
		};

		return Test;
	})(Component);
	apivm.define("test", Test);
	apivm.render(apivm.h("test", null), "body");
})();

	window['createApp'] = function() {
		apivm.$_start();
	}
	return avm;
}